#ifndef COLLAPSE_GUI_STYLE_H
#define COLLAPSE_GUI_STYLE_H

#include "GUI.h"
#include "SpriteBatch.h"
#include "BitmapFont.h"
#include "Colors.h"

using namespace Cvekas;

class CollapseGUIStyle : public GUIStyle
{
public:
	CollapseGUIStyle(SpriteBatchPtr sprite_batch, TextureManagerPtr texture_manager, BitmapFontPtr font, uint layer = 0);
	~CollapseGUIStyle();

	virtual bool hitButton(const Vector2& pos, const std::string& text);
	virtual bool hitSwitch(const Vector2& pos, const std::string& text);
	virtual float hitSlider(const Vector2& pos);
	virtual bool hitSelector(const Vector2& pos, const std::vector<std::string>& selections, uint& button);

	virtual void drawLabel(const Vector2& pos, const std::string& text);
	virtual void drawButton(const Vector2& pos, const std::string& text, bool mouse_over, bool pressed);
	virtual void drawSwitch(const Vector2& pos, const std::string& text, bool mouse_over, bool state);
	virtual void drawSlider(const Vector2& pos, bool mouse_over, float state);
	virtual void drawSelector(const Vector2& pos, const std::vector<std::string>& selections, uint item, 
		bool mouse_over, bool mouse_over_prev, bool mouse_over_next, bool pressed);

	virtual void endFrame();

	// TODO: add similar functions for all widgets
	// Helper for nice menu state fading
	void drawSimpleSlider(const Vector2& pos, float state, const Color& color);

private:
	float calcSelectorWidth(const std::vector<std::string>& selections);

	struct SelectorState
	{
		float width;
		float prev_shift;
		float next_shift;
	};

	union WidgetState
	{
		float shift;
		SelectorState selector;
	};

	SpriteBatchPtr sprite_batch;
	uint layer;

	Texture2DPtr texture;
	BitmapFontPtr font;

	StaticHashMap<WidgetState, uint, GUI::cache_size> cache;
};

typedef boost::shared_ptr<CollapseGUIStyle> CollapseGUIStylePtr;

#endif